package com.business_clean.viewmodel.request

import androidx.lifecycle.MutableLiveData
import com.business_clean.app.config.Constant.PAGE_SIZE
import com.business_clean.app.network.NetUrl
import com.business_clean.data.mode.custom.CustomMangerDetailEntity
import com.business_clean.data.mode.custom.CustomMangerEntity
import com.business_clean.data.mode.custom.CustomMangerList
import me.hgj.mvvmhelper.base.BaseViewModel
import me.hgj.mvvmhelper.ext.rxHttpRequest
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse
import java.util.HashMap

class CustomViewModel : BaseViewModel() {

    var customMangerList = MutableLiveData<CustomMangerEntity>()

    var customDetail = MutableLiveData<CustomMangerList>()

    var update = MutableLiveData<Any>()

    //合作的项目
    var cooperateList = MutableLiveData<CustomMangerDetailEntity>()

    //删除客户
    var delete = MutableLiveData<Any>()


    /**
     * 获取列表
     */
    fun getCustomList(page: Int) {
        rxHttpRequest {
            onRequest = {
                customMangerList.value = RxHttp.get(NetUrl.GET_CUSTOM_LIST)
                    .add("page", page)
                    .add("size", PAGE_SIZE)
                    .toResponse<CustomMangerEntity>().await()
            }
        }
    }


    /**
     * 添加 或者 编辑客户
     */
    fun saveCustomInfo(hashMap: HashMap<String, String>) {
        rxHttpRequest {
            onRequest = {
                update.value = RxHttp.get(NetUrl.SAVE_CUSTOM)
                    .addAll(hashMap)
                    .toResponse<Any>().await()
            }
        }
    }


    /**
     * 获取项目的列表
     */
    fun getProjectMangerAllList(page: Int, custom_uuid: String? = null) {
        rxHttpRequest {
            onRequest = {
                cooperateList.value = RxHttp.get(NetUrl.GET_PROJECT_MANGER_ALL)
                    .add("page", page)
                    .add("size", PAGE_SIZE)
                    .add("custom_uuid", custom_uuid)
                    .toResponse<CustomMangerDetailEntity>().await()
            }
        }
    }

    /**
     * 删除客户
     */
    fun requestDetails(uuid: String? = null) {
        rxHttpRequest {
            onRequest = {
                customDetail.value = RxHttp.get(NetUrl.GET_CUSTOM_DETAILS)
                    .add("uuid", uuid)
                    .toResponse<CustomMangerList>().await()
            }
        }
    }


    /**
     * 删除客户
     */
    fun deleteCustom(custom_uuid: String? = null) {
        rxHttpRequest {
            onRequest = {
//                delete.value = RxHttp.get(NetUrl.getProjectMangerList)
//                    .add("page", page)
//                    .add("size", PAGE_SIZE)
//                    .add("custom_uuid", custom_uuid)
//                    .toResponse<CustomMangerEntity>().await()
            }
        }
    }
}